/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : Apr 4, 2012  4:43:18 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : jpa.service.promis.sales
 * File Name : VwSyncMktCustBookContServices.java
 * TODO
 */
package jpa.service.promis.sales;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import jpa.entitys.promis.sales.VwSyncMktCustBookCont;
import jpa.service.common.JPAService;

/**
 * @author chatree
 *
 */
public class VwSyncMktCustBookContServices extends JPAService {
	
	private static final Logger log = Logger.getLogger(VwSyncMktCustBookContServices.class);

	/**
	 * @param em
	 */
	public VwSyncMktCustBookContServices(EntityManager em) {
		super(em);
		// TODO Auto-generated constructor stub
	}
	
	public VwSyncMktCustBookCont findById(String id) throws Exception {		
		
		return super.ConvertToYoureObject(super.find(id, "VwSyncMktCustBookCont.findById"));
	}
	
	public List<VwSyncMktCustBookCont> findAll() throws Exception {
		return super.ConvertToYoureObject(super.findAll("VwSyncMktCustBookCont.findAll"));
	}
	
	
	public List<VwSyncMktCustBookCont> findByDocumentNo(String company, String project ,String documentNo, String status, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company); 					//log.info("company=" + company);
		mapWhereValue.put("project", project);					//log.info("project=" + project);
		mapWhereValue.put("documentNo", documentNo);			//log.info("documentNo=" + documentNo);
		
		if(!CommonService.IsNull(status))
			mapWhereValue.put("status", status);					//log.info("status=" + status);
		else
			return super.ConvertToYoureObject(super.find("VwSyncMktCustBookCont.findByDocumentNo2", mapWhereValue));
				
		if(!CommonService.IsNull(syncIsstaging)){
			mapWhereValue.put("syncIsstaging", syncIsstaging);
			return super.ConvertToYoureObject(super.find("VwSyncMktCustBookCont.findByDocumentNo1", mapWhereValue));
		}else
			return super.ConvertToYoureObject(super.find("VwSyncMktCustBookCont.findByDocumentNoNoIsSync1", mapWhereValue));
	}
	
	public List<VwSyncMktCustBookCont> findByDocumentNo(String company, String project ,String documentNo, String syncIsstaging) throws Exception {
		Map<String,Object> mapWhereValue = new HashMap<String, Object>();				
		mapWhereValue.put("company", company); 					//log.info("company=" + company);
		mapWhereValue.put("project", project);					//log.info("project=" + project);
		mapWhereValue.put("documentNo", documentNo);			//log.info("documentNo=" + documentNo);
		
		if(!CommonService.IsNull(syncIsstaging)){
			mapWhereValue.put("syncIsstaging", syncIsstaging);
			
			return super.ConvertToYoureObject(super.find("VwSyncMktCustBookCont.findByDocumentNo", mapWhereValue));
		}else
			return super.ConvertToYoureObject(super.find("VwSyncMktCustBookCont.findByDocumentNoNoIsSync", mapWhereValue));
	}
	

}
